<script>
export default {
    getVideoLength(second){
        second = Math.ceil(second)

        let s = second % 60
        s = s > 9 ? s : '0' + s

        let minute = Math.floor(second / 60)

        let m = minute % 60
        m = m > 9 ? m : '0' + m

        let hour = Math.floor(minute / 60)

        let h = hour > 0 ? hour + ':' : ''

        return h + m + ':' + s
    },
    /**
     * @param {ratio} Integer 当前播放比率
     * @return second 当前时间
     */
    setVideoLength(ratio,duration){
        return duration * (ratio / 100)
    },
    /**
     * 进入全屏
     * 此方法不可以在異步任務中執行，否則火狐無法全屏
     */
    launchFullscreen(element){
        if(element.requestFullscreen) {
            element.requestFullscreen();
        } else if(element.mozRequestFullScreen) {
            element.mozRequestFullScreen();
        } else if(element.msRequestFullscreen){ 
            element.msRequestFullscreen();  
        } else if(element.oRequestFullscreen){
            element.oRequestFullscreen();
        }else if(element.webkitRequestFullscreen){
            element.webkitRequestFullScreen();
        }else{
            var docHtml  = document.documentElement;
            var docBody  = document.body;
            var videobox  = document.getElementById('videobox');
            var  cssText = 'width:100%;height:100%;overflow:hidden;';
            docHtml.style.cssText = cssText;
            docBody.style.cssText = cssText;
            videobox.style.cssText = cssText+';'+'margin:0px;padding:0px;';
            document.IsFullScreen = true;
        }
    },
    /**
     * 退出全屏
     */
    exitFullscreen(){
        if (document.exitFullscreen) {
            document.exitFullscreen();
        } else if (document.msExitFullscreen) {
            document.msExitFullscreen();
        } else if (document.mozCancelFullScreen) {
            document.mozCancelFullScreen();
        } else if(document.oRequestFullscreen){
            document.oCancelFullScreen();
        }else if (document.webkitExitFullscreen){
            document.webkitExitFullscreen();
        }else{
            var docHtml  = document.documentElement;
            var docBody  = document.body;
            var videobox  = document.getElementById('videobox');
            docHtml.style.cssText = "";
            docBody.style.cssText = "";
            videobox.style.cssText = "";
            document.IsFullScreen = false;
        }
    }
}
</script>